package sg.nus.iss.vmcs.guilisteners;

import java.awt.Checkbox;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

import sg.nus.iss.vmcs.controllers.MachineryController;

/**
 * Action Listener for the Door Listener in the Machinery Panel<br><br>
 * Modifications:
 * <li>Philip - 28/12/2010 - Removed temporary variables in itemStateChanged</li>
 * <br><br>
 * @author Pang Pingli
 * @author Philip Chew
 */
public class DoorListener implements ItemListener {
	
	/** Machinery Controller */
	private MachineryController  mCtrl;
	
	/**
	 * Creates a new instance of the Door Listener
	 * @param mc Reference to store controller
	 */
	public DoorListener(MachineryController mCtrl) {
		this.mCtrl = mCtrl;
	}

	/**
	 * Implementation of itemStateChanged
	 * When checkbox is false, door is open, when true, door is closed
	 */
	public void itemStateChanged(ItemEvent e) {
		if(e.getSource() instanceof Checkbox) {
			mCtrl.setDoorStatus(((Checkbox)e.getSource()).getState());
		}
	}
}